<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<style>
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(to right, #eef1f4, #3498db);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    /* 确保 header 在最上层 */
    height: 60px;
    font-size: 20px;
    font-weight: bold;
    border-bottom: 1px solid #ccc;
  }

  .user-info {
    display: flex;
    align-items: center;
    margin-right: 40px;
  }

  .dropdown-toggle {
    font-size: 14px;
    cursor: pointer;
  }

  .dropdown-menu {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 60px;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
    z-index: 1;
  }

  .dropdown:hover .dropdown-menu {
    display: block;
  }

  .menu-item {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 14px;
  }

  .menu-item:hover {
    background-color: #f1f1f1;
  }
</style>


<div class="header">
  <h4 style="color:black;margin-left: 40px"><c:out value="${course_key.title}"/></h4>
  <div class="user-info">
    <img src="${user_key.avatar}" style="width: 30px;border-radius:50%;margin-right: 10px;">
    <div class="dropdown">
      <span class="dropdown-toggle">${user_key.nickname} &#9660;</span>
      <div class="dropdown-menu">
        <a class="menu-item" href="../Index.jsp">个人空间</a>
        <a class="menu-item" href="javascript:void(0)" onclick="handleLogout()">退出</a>
      </div>
    </div>
  </div>
</div>

<script>

  function handleLogout() {
    var xhr = new XMLHttpRequest()
    xhr.onload = function () {
      if (xhr.status === 200) {
        window.location.href = "../Login.jsp"
      }
    }

    xhr.open("POST", "/day_day_up/account?type=2", true)
    xhr.send()
  }
</script>

